package observer_2.weather.observer;

import observer_2.weather.DisplayElement;
import observer_2.weather.Observer;
import observer_2.weather.Subject;

/**
 * Created by zjh on 2017/9/19.
 */
public class CurrentConditionsDisplay implements Observer, DisplayElement{

    private float temperature;
    private float humidity;

    private Subject weathreData;


    public CurrentConditionsDisplay(Subject weathreData) {
        this.weathreData = weathreData;
        weathreData.registerObserver(this);//todo 没有构造完就把当前对象发布出去了，这样是不对的
    }

    public void update(float temperature, float humidity, float pressure) {
        this.temperature = temperature;
        this.humidity = humidity;
        display();
    }

    public void display() {
        System.out.println("Current conditions: " + temperature + "F degrees and " + humidity + "% humidity");
    }
}
